package cn.deepmax.spring.cloud.common.data;

import javax.persistence.AttributeConverter;
import java.sql.Timestamp;
import java.time.LocalDateTime;

public class LocalDateTimeAttributeConverter implements AttributeConverter<LocalDateTime, Timestamp> {

    public LocalDateTimeAttributeConverter() {
    }


    @Override
    public LocalDateTime convertToEntityAttribute(Timestamp dbData) {
        return dbData==null?null: dbData.toLocalDateTime();
    }

    @Override
    public Timestamp convertToDatabaseColumn(LocalDateTime attribute) {

        return attribute==null ? null : Timestamp.valueOf(attribute);
    }

}
